#!/bin/bash

imageName=$1
echo ${imageName}

cd /opt/sh/deploy \
&& rm -f jar/* \
&& find /opt/jar -name deploy-service.jar -exec cp {} jar/ \; \
&& docker image build -t ${imageName} .

CID=$(docker ps -a| grep deploy | awk '{print $1}')
if [ -z "$CID" ]
then
    echo docker container is not exists
else
    echo remove $CID
    docker stop $CID
    docker rm $CID
fi
docker run -d -p 8002:8002 -v /opt/logs:/opt/logs --name deploy-${imageName} ${imageName} /bin/bash